<extend name="Layout/application"/>

<!-- content start -->
<block name="content">
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf">
                    <strong class="am-text-primary am-text-lg">编辑通知</strong> /
                    <small>Edit Notice</small>
                </div>
            </div>

            <hr>
            <form class="am-form" action="{{:URL('HomNotice/update',['id'=>$notice.id])}}" method="post">
                <div data-am-tabs>

                    <div class="am-tabs-bd">
                        <div class="am-form am-tab-panel am-fade am-in am-active" id="tab1">


                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">通知标题</div>
                                <div class="am-u-sm-8 am-u-md-3 am-u-end col-end">
                                    <input type="text" class="am-input-sm" name="title" value="{{$notice->title}}">
                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">所属分类</div>
                                <div class="am-u-sm-8 am-u-md-10">
                                    <select name="notice_node_id" data-am-selected="{btnSize: 'sm'}">
                                        <option value="">请选择
                                            <volist name="nodes" id="node">

                                        <option value="{{$node->id}}"
                                        <eq name="node.id" value="$notice.notice_node_id"> selected </eq>
                                        >{{$node->name}}</option>
                                        </volist>

                                        </option>
                                    </select>
                                </div>
                            </div>


                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-2 am-text-right">描述信息</div>
                                <div class="am-u-sm-8 am-u-md-3 am-u-end col-end">
                                    <textarea name="body" id="" cols="11" rows="7">{{$notice->body}}</textarea>
                                </div>
                            </div>


                        </div>
                    </div>
                    <div class="am-margin">
                        <button type="submit" class="am-btn am-btn-primary am-radius">提交保存</button>
                    </div>

                </div>
            </form>

        </div>
    </div>

    <footer class="admin-content-footer">
        <hr>
        <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
    </footer>
    <!-- content end -->
</block>
<block name="js">
    <script src="__PUBLIC__/vendor/bootstrapextend/js/bootstrap.extend.js"></script>
    <script src="__PUBLIC__/vendor/validate/jquery.validate.js"></script>
    <script src="__PUBLIC__/vendor/validate/localization/messages_zh.js"></script>
    <script>
        $(function () {

            $(".am-form").validate({
                onfocusout: function (element) {
                    $(element).valid();
                }
            })


            //给上传图片按钮绑定事件
            $('.new_thumb').click(function () {
                $("#file_upload_1-button").click();
            })


            //上传单张
            $('#upload_one').Huploadify({
                uploader: '{{:U("Admin/Uploadfile/upload")}}',
                fileTypeExts: '*.gif;*.jpg;*.jpeg;*.png;*.bmp',
                //fileSizeLimit:{:C('UPLOAD_IMAGE_SIZE')}*1024,
                buttonText: '上 传 图 片',
                onUploadComplete: function (file, data) {
                    data = $.parseJSON(data);
                    $('#view_one img').attr('src', data.real_path);
                    $('#view_one input').attr('value', data.real_path);

                }
            });


            //上传多张
            $('#upload_more').Huploadify({
                uploader: '{{:U("Admin/Uploadfile/upload")}}',
                fileTypeExts: '*.gif;*.jpg;*.jpeg;*.png;*.bmp',
//                fileSizeLimit:{:C('UPLOAD_IMAGE_SIZE')}*1024,
                buttonText: '上传多张图片',
                onUploadComplete: function (file, data) {
                    var data = $.parseJSON(data);
                    //console.log(data);
                    if (data.error == 1) {
                        alertMessager(data.message);
                    } else {
                        var input = $('#view_more input');
                        var new_img = '<span class="img-box">' +
                            '<img class="img img-responsive" width="80" src="' + data.real_path + '">' +
                            '<a class="label label-danger remove-picture" href="javascript:void(0);" >删除</a>' +
                            '<input type="hidden" name="gallery[]" value="' + data.real_path + '">' +
                            '</span>';
                        $('#view_more').append(new_img);
                    }
                }
            });

            //删除图片 <i class="glyphicon glyphicon-remove-sign remove-picture"></i>
            $('#view_more').on('click', '.remove-picture', function () {
                var ready_for_remove_id = $(this).closest('.img-box').find('img').attr('data-id'); //获取待删除的图片ID
                if (!ready_for_remove_id) {
                    alertMessager('错误');
                }
                var current_picture_ids = $('#view_more input').val().split(","); //获取当前图集以逗号分隔的ID并转换成数组
                current_picture_ids.remove(ready_for_remove_id); //从数组中删除待删除的图片ID
                $('#view_more input').val(current_picture_ids.join(',')) //删除后覆盖原input的值
                $(this).closest('.img-box').remove(); //删除图片预览图
            });
        });
    </script>

</block>


